package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.*;
import com.llgz.hotelmanageapi.pojo.DO.CommodityInfo;
import com.llgz.hotelmanageapi.pojo.DO.CommodityInfo;
import com.llgz.hotelmanageapi.pojo.DO.CommodityInfo;
import com.llgz.hotelmanageapi.service.impl.CommodityInfoServiceImpl;
import com.llgz.hotelmanageapi.service.impl.CommodityInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/commodityInfo")
@Api("商品信息")
@RequiresRoles(value = {"root", "admin", "manager", "reception"}, logical = Logical.OR)
public class CommodityInfoController {
    @Autowired
    CommodityInfoServiceImpl commodityInfoService;

    /**
     * @MethodName addCommodityInfo
     * @Params * @param CommodityInfo
     * @Description 添加
     * @Return CommonResult
     */
    @PostMapping("/addCommodityInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addCommodityInfo(@RequestBody CommodityInfo commodityInfo){
        boolean save = commodityInfoService.save(commodityInfo);
        return CommonResult.successResponse(save);
    }
    /**
     * @MethodName getCommodityInfoList
     * @Params * @param CommodityInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @GetMapping("/getCommodityInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getCommodityInfoList(@RequestParam String query,@RequestParam Integer pageNum,@RequestParam Integer pageCount){
        QueryWrapper<CommodityInfo> queryWrapper = new QueryWrapper<>();
        if (query != null && !query.isEmpty()){
            queryWrapper.like("commodity_name",query);
        }
        IPage<CommodityInfo> page = commodityInfoService.page(new Page<>(pageNum, pageCount), queryWrapper);
        return CommonResult.successResponse(page);
    }
    @GetMapping("/getCommodityInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getCommodityInfoById(@RequestParam String id){
        CommodityInfo category = commodityInfoService.getOne(new QueryWrapper<CommodityInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }
    /**
     * @MethodName updateCommodityInfo
     * @Params * @param CommodityInfo
     * @Description 更新
     * @Return CommonResult
     */
    @PostMapping("/updateCommodityInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateCommodityInfo (@RequestBody CommodityInfo commodityInfo){
        boolean b = commodityInfoService.updateById(commodityInfo);
        return CommonResult.successResponse(b);
    }
//    /**
//     * @MethodName deleteCommodityInfo
//     * @Params * @param CommodityInfo
//     * @Description 删除
//     * @Return CommonResult
//     */
//    @PostMapping("/deleteCommodityInfo")
//    @ApiOperation(value = "删除", response = CommonResult.class, httpMethod = "POST")
//    public CommonResult deleteCommodityInfo (@RequestParam String id){
//        boolean b = commodityInfoService.removeById(id);
//        return CommonResult.successResponse(b);
//    }
    /**
     * @MethodName deleteCommodityInfo
     * @Params * @param CommodityInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteCommodityInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteCommodityInfo (@RequestBody List<String> ids){
        boolean b = commodityInfoService.removeByIds(ids);
        return CommonResult.successResponse(b);
    }
}

